package cn.hg.solon.youcan.framework.listener;

import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.event.EventListener;

import cn.hg.solon.youcan.common.util.AddressUtil;
import cn.hg.solon.youcan.system.entity.SysUserLogin;
import cn.hg.solon.youcan.system.service.SysUserLoginService;

/**
 * @author 胡高
 */
@Component
public class LoginLogEventListener implements EventListener<SysUserLogin> {

    @Inject
    SysUserLoginService userLoginService;

    @Override
    public void onEvent(SysUserLogin login) throws Throwable {
        login.setLocation(AddressUtil.getRealAddressByIP(login.getIp()));

        this.userLoginService.save(login);
    }

}
